import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class FinancialCenterStore extends LoadHoc {
  /**
   * 查询工程项目信息
   */
  @observable allProjectInfo: api.YNJWTFinancialCenterVOProjectInfoMiniVO = {};
  @loading @action
  async getAllProjectInfo(params: {
    provinceId: number,
    cityId:number,
    districtId:number,
    pageIndex:number,
    pageSize: number,
    callback?: (allProjectInfo: api.YNJWTFinancialCenterVOProjectInfoMiniVO) => void;
  }) {
    const {provinceId,cityId,districtId,pageSize,pageIndex,callback} = params;
    const allProjectInfo = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetAllProjectInfoAsync({
      formProvinceId:provinceId,
      formCityId:cityId,
      formDistrictId:districtId,
      formSkipCount:(pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.allProjectInfo = allProjectInfo;
    callback && callback(allProjectInfo);
  }

  /**
   * 查询工程项目详细信息
   */
  @observable projectInfo: api.YNJWTFinancialCenterVOProjectInfoVO = {};
  @loading @action
  async getProjectInfo(params: {
   id:number,
    callback?: (projectInfo: api.YNJWTFinancialCenterVOProjectInfoVO) => void;
  }) {
    const {id,callback} = params;
    const projectInfo = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetProjectInfoAsync({
     formId:id
    }));
    this.projectInfo = projectInfo;
    callback && callback(projectInfo);
  }

  /**
   * 保存工程项目信息
   */
  @loading @action
  async saveProjectInfo(params: {
    form: {
      projectName: string,
      projectType: string,
      area: string,
      areaCode: number,
      allAreaCode: string,
      projectPrice: number,
      companyName: string,
      natureOfTheFirm: string,
      enterpriseScale: string,
      enterpriseQualification: string,
      taxTypes: string,
      enterpriseAddress: string,
      remarks: string,
      contactsName: string,
      phoneNumnber: string,
      wechatNumber: string,
      qqNumber: string,
    },
    callback?: () => void;
  }) {
    const {form,callback} = params;
    await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveProjectInfoAsync({
      form
    }));
    callback && callback();
  }

  /**
   * 查询工商服务中心所有动态信息
   */
  @observable allCompanyTaxReturn: api.YNJWTFinancialCenterVOCompanyTaxReturnVO = {};
  @loading @action
  async getAllCompanyTaxReturn(params: {
    pageIndex:number,
    pageSize: number,
    callback?: (allCompanyTaxReturn: api.YNJWTFinancialCenterVOCompanyTaxReturnVO) => void;
  }) {
    const {pageIndex,pageSize,callback} = params;
    const allCompanyTaxReturn = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetAllCompanyTaxReturnAsync({
      formSkipCount:(pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.allCompanyTaxReturn = allCompanyTaxReturn;
    callback && callback(allCompanyTaxReturn);
  }

  /**
   * 保存工商服务中心信息
   */
  @loading @action
  async saveCompanyTaxReturn(params: {
    form: {
      companyName: string,
      businessScope: string,
      registrationAddress: string,
      registeredCapital: string,
      shareholdingRatio: string,
      categoriesOfApplications: string,
      applicationLevel: string,
      certificateIMG: string,
      openAnAccountIMG: string,
      iDcardImg: string,
      institutionalFrameworkIMG: string,
      registerImg: string,
      contactsName: string,
      phoneNumnber: string,
      emailAddress: string,
      address: string,
      type: any,
    },
    callback?: (res) => void;
  }) {
    const {form,callback} = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveCompanyTaxReturnAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 查询建企资质服务中心信息
   */
  @observable allQualificationServiceCenterInfo: api.YNJWTFinancialCenterVOQualificationServiceVO = {};
  @loading @action
  async getAllQualificationServiceCenterInfo(params: {
    qualificationsType: number,
    areaCode: number,
    pageIndex:number,
    pageSize: number,
    callback?: (res: api.YNJWTFinancialCenterVOQualificationServiceVO) => void;
  }) {
    const {qualificationsType,areaCode,pageIndex,pageSize,callback} = params;
    const allQualificationServiceCenterInfo = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetAllQualificationServiceCenterInfoAsync({
      formQualificationsType: qualificationsType,
      formAreaCode: areaCode,
      formSkipCount:(pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.allQualificationServiceCenterInfo = allQualificationServiceCenterInfo;
    callback && callback(allQualificationServiceCenterInfo);
  }

  /**
   * 查询建企资质服务中心信息-详情
   */
  @observable qualificationServiceCenterInfo: api.YNJWTFinancialCenterVOQualificationServiceVO = {};
  @loading @action
  async getQualificationServiceCenterInfo(params: {
    formId: number,
    callback?: (res: api.YNJWTFinancialCenterVOQualificationServiceVO) => void;
  }) {
    const {formId,callback} = params;
    const qualificationServiceCenterInfo = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetQualificationServiceCenterInfoAsync({
      formId
    }));
    this.qualificationServiceCenterInfo = qualificationServiceCenterInfo;
    callback && callback(qualificationServiceCenterInfo);
  }

  /**
   * 保存建企资质服务中心信息
   */
  @loading @action
  async saveQualificationServiceCenter(params: {
    form: {
      title: string,
      qualificationsType: api.YNJWTFinancialCenterFormQualificationServiceVOFormQualificationsTypeEnum,
      priceInterval: string,
      qualificationLevel: string,
      taxpayerType: string,
      remarks: string,
      contactsName: string,
      contactsPhone: string,
      contactsWechat: string,
      contactsQQ: string,
      contactsArea: string,
      areaCode: number,
    },
    callback?: (res) => void;
  }) {
    const {form,callback} = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveQualificationServiceCenterAsync({
     form
    }));
    callback && callback(res);
  }



  /**
   * 保存工程项目预约
   */
  @loading @action
  async saveProjectSubscribe(params: {
    form: {
      projectName: string,
      projectType: string,
      needMoney: number,
      address: string,
      timeLimit: string,
      principal: string,
      phoneNumber: string,
      emailAddress: string,
    },
    callback?: (res) => void;
  }) {
    const {form,callback} = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveProjectSubscribeAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 保存工程现金
   */
  @loading @action
  async saveProjectCashcs(params: {
    form: {
      projectName: string,
      constructionEnterprise: string,
      guaranteeSum: number,
      address: string,
      enterpriseSituation: string,
      projectType: string,
      timeLimit: string,
      enterpriseQualification: string,
      material: string,
      principal: string,
      phoneNumber: string,
      emailAddress: string,
    },
    callback?: (res) => void;
  }) {
    const {form,callback} = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveProjectCashcsAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 工程金融中心项目数量
   */
  @loading @action
  async getCount(params: {
    callback?: (res: api.YNJWTFinancialCenterVOCountVO) => void;
  }) {
    const { callback } = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetCountAsync({
    }));
    callback && callback(res);
  }

  /**
   * 工商服务中心项目数量
   */
  @loading @action
  async getCompanyTaxReturnCount(params: {
    callback?: (res: api.YNJWTFinancialCenterVOCompanyTaxReturnCountVO) => void;
  }) {
    const { callback } = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterGetCompanyTaxReturnCountAsync({
    }));
    callback && callback(res);
  }

  /**
   * 保存保函信息第一步
   */
  @loading @action
  async saveInfoAndCalculationMoney(params: {
    form: {
      typeOfInsurance: string,
      companyName: string,
      amount: number,
      countryOrArea: string,
      enterpriseSituation: string,
      projectType: string,
      constructionPeriod: string,
      enterpriseQualification: string
    },
    callback?: (res: api.YNJWTFinancialCenterVOMoneyVO) => void;
  }) {
    const { form, callback } = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveInfoAndCalculationMoneyAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 保存保函信息第二步
   */
  @loading @action
  async saveSuretyBondInfo(params: {
    form: {
      id,
      qualificationLevel: string,
      relatedInformation: string,
      personInCharge: string,
      phoneNumber: string,
      emailAddress: string,
      isChooseBank: boolean,
      bankName: string,
      isAboutArchitecur: boolean,
    },
    callback?: (res) => void;
  }) {
    const { form, callback } = params;
    const res = await request(api.AppfinancialCenterApiFetchParamCreactor.appfinancialCenterSaveSuretyBondInfoAsync({
      form
    }));
    callback && callback(res);
  }
}
